package com.yyw.h5gameqianguoshu;


import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.yyw.game.R;

public class MainerActivity extends Activity {

    @RequiresApi(api = Build.VERSION_CODES.P)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //去掉titile bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);


        setContentView(R.layout.activity_main);


        hideBottomUIMenu();
        //fullscreen(false);
    }


    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        // TODO Auto-generated method stub
        super.onWindowFocusChanged(hasFocus);
        // hideBottomUIMenu();
    }






    /**
     * 隐藏虚拟按键，并且全屏
     */


    protected void hideBottomUIMenu(){
        //隐藏虚拟按键，并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            View v = this.getWindow().getDecorView();
            v.setSystemUiVisibility(View.GONE);
        } else if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 28) {
            Toast.makeText(this,"api dayu 19",Toast.LENGTH_SHORT).show();
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                    | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                    | View.SYSTEM_UI_FLAG_IMMERSIVE;//拉出来，几秒不操作自己不会弹回去
            decorView.setSystemUiVisibility(uiOptions);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        }else if (Build.VERSION.SDK_INT >= 28) {
            Toast.makeText(this,"api dayu 28",Toast.LENGTH_SHORT).show();
            //for new api versions.
            View decorView = getWindow().getDecorView();
            int uiOptions =
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE     // 注释和不注释没有变化
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // 注释和不注释没有变化
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN   // 注释和不注释没有变化
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar 隐藏导航栏
                    | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar 全屏  即隐藏电量 状态栏.但是刘海屏有黑边，需要配合安卓10属性
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY //拉出来，几秒不操作自己弹回去
                    ;
            decorView.setSystemUiVisibility(uiOptions);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;

        }
    }

}
